﻿namespace MVVMBasedDialogs.ViewModel
{
    using GalaSoft.MvvmLight;
    using System.Windows.Input;
    using GalaSoft.MvvmLight.Command;
    using System.Windows;
    
    internal class MainViewModelWithDialogService : ViewModelBase
    {
        IDialogService _applicationDialogService;
        public IDialogService ApplicationDialogService
        {
            get
            {
                if (_applicationDialogService == null)
                {
                    _applicationDialogService = new DialogService();
                }

                return _applicationDialogService;
            }
            internal set 
            {
                _applicationDialogService = value;
            }
        }

        string _welcome = "Dialogs & MVVM";
        public string Welcome
        {
            get
            {
                return _welcome;
            }
            set
            {
                _welcome = value;
                RaisePropertyChanged("Welcome");
            }
        }

        ICommand _showDialogCommand;
        public ICommand ShowDialogCommand
        {
            get
            {
                if (_showDialogCommand == null)
                {
                    _showDialogCommand = new RelayCommand(ShowMessage);
                }

                return _showDialogCommand;
            }
        }

        internal void ShowMessage()
        {
            MessageBoxResult result = 
                ApplicationDialogService.ShowMessageBox("Message", 
                                "Message Header", MessageBoxButton.OK);

            Welcome = EvaluateText(result);
        }

        protected virtual string EvaluateText(MessageBoxResult result)
        {
            string msg =  System.Enum.GetName(typeof(MessageBoxResult), result);
            return msg;
        }
    }
}
